package com.example.yls.demoa;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.RequiresApi;

public class MyFrontService extends Service {
    public MyFrontService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onCreate() {
        super.onCreate();
        Intent intent = new Intent(MyFrontService.this,MainActivity.class);
        PendingIntent pi = PendingIntent.getActivity
                (MyFrontService.this,0,intent,0);

        Notification notification = new Notification.Builder(MyFrontService.this)
                .setContentTitle("标题")
                .setContentText("内容")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setWhen(System.currentTimeMillis())
                .setContentIntent(pi)
                .build();
            startForeground(1,notification);



    }
}
